# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: jaewon

import logging

from absl import app, flags

from coin.strategy.mm.simple_sim.result_util import load_sim_result
from coin.strategy.mm.simple_sim.runner_util import get_profile_module


def main(argv):
  FLAGS = flags.FLAGS

  assert FLAGS.profile is not None
  assert FLAGS.result_dir is not None

  try:
    profile_args = argv[1:]
    profile = get_profile_module(FLAGS.profile, profile_args)
  except ModuleNotFoundError:
    return 2

  result_dirs = FLAGS.result_dir.split(',')
  results = load_sim_result(result_dirs)
  profile.aggregate_result(results)


if __name__ == '__main__':
  logging.basicConfig(
      level='DEBUG',
      format='%(levelname)8s %(asctime)s %(name)s %(filename)s:%(lineno)d] %(message)s')
  logging.getLogger('coin.exchange.util.feed_checker').setLevel(logging.WARNING)

  flags.DEFINE_string('profile', None, 'Profile name')
  flags.DEFINE_string(
      'result_dir',
      None,
      'Result directory. Multiple directories can be specified by separating '
      'with comma.')
  app.run(main)
